<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0px;
        padding: 0px;
      }
      .box {
        width: 100px;
        border: 2px solid #000;
        overflow: hidden;
        position: absolute;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <span>x</span>
      <span>y</span>
    </div>
  </body>
</html>
<script>
  var boxs = document.getElementsByClassName("box")[0];
  var spans = document.querySelectorAll("span");
  document.onmousemove = function (e) {
    spans[0].innerHTML = "x:" + e.clientX;
    spans[1].innerHTML = "y:" + e.clientY;
    boxs.style.left = e.clientX + "px";
    boxs.style.top = e.clientY + "px";
  };
</script>
